package fge;

import com.l2fprod.common.beans.editor.AbstractPropertyEditor;
import com.l2fprod.common.swing.LookAndFeelTweaks;
import java.awt.Font;
import javax.swing.JLabel;

/**
 * A custom property editor that defers the change to the CodeEditor instead
 */
public class FuncPropertyField extends AbstractPropertyEditor {

	private Function func;

	public FuncPropertyField() {
		editor = new JLabel("");

		Font old_font = ((JLabel) editor).getFont();
		Font new_font = new Font(old_font.getName(), Font.PLAIN, old_font.getSize());
		((JLabel) editor).setFont(new_font);
		((JLabel) editor).setBorder(LookAndFeelTweaks.EMPTY_BORDER);
		((JLabel) editor).setText(Function.propertyMessage());
	}
	
	/**
	 * Called when the user has entered the new value in the property field,
	 * ie. when the user presses enter or leaves the field.
	 * @return 
	 */
	@Override
	public Object getValue() {
		/**
		 * We have to return something since the property editor make checks, 
		 * so we just return what we got in the first place
		 */
		return this.func;
	}

	/**
	 * Called when the user clicks to edit the property field
	 * @param value The value returned by Fcomponent::getFunc(). This is determined by the BeanInfo.
	 */
	@Override
	public void setValue(Object _value) {
		this.func = ((Function) _value);
		func.getComp().openEditor();
	}
}
